/* ttybug/ttybug.c
 *
 * Terminal debug
 *
 * Copyright (c) 2011 by BKIT4U <www.bkit4u.com>
 * Author: BS135 <thanhhai135@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General  Public  License
 * as published by the Free Software Foundation;version 2 or 2.1
 * of the License. This license can be found at
 *                           http://www.gnu.org/licenses/gpl.txt
 *
 * Target MCU	: Atmel AVR series
 * Editor Tabs	: 4
 */

#include "uart.h"
#include <stdio.h>

static int uart_putchar(char c, FILE *stream);
static int uart_getchar(FILE *stream);
static FILE mystdio = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);


static int uart_putchar(char c, FILE *stream)
{
	if (c == '\n')
		uart_putchar('\r', stream);
	uart_transmit_byte(c);
	return 0;
}

static int uart_getchar(FILE *stream)
{
	return uart_receive_byte();
}


void ttybug_init()
{
	//set stand input/output
	stdout = &mystdio;
	stdin  = &mystdio;
}
